package com.atguigu.srb.core.controller.api;


import com.atguigu.guigu.common.result.R;
import com.atguigu.service.base.utils.JwtUtils;
import com.atguigu.srb.core.pojo.entity.LendItemReturn;
import com.atguigu.srb.core.pojo.entity.LendReturn;
import com.atguigu.srb.core.service.LendItemReturnService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 标的出借回款记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-11-19
 */
@RestController
@RequestMapping("/api/core/lendItemReturn")
public class ApiLendItemReturnController {
    @Resource
    LendItemReturnService lendItemReturnService;
    @ApiOperation("获取登录用户的回款计划")
    @GetMapping("/lend/{lendId}")
    public R list(@PathVariable("lendId")String lendId,
                  @RequestHeader(value = "token" , required = false)String token){
        Long userId = JwtUtils.getUserId(token);
        List<LendItemReturn> lendItemReturns = lendItemReturnService.list(Wrappers.lambdaQuery(LendItemReturn.class)
                .eq(LendItemReturn::getLendId, lendId)
                .eq(LendItemReturn::getInvestUserId , userId)
                .orderByAsc(LendItemReturn::getCurrentPeriod));
        return R.ok().data("items",lendItemReturns);
    }
}

